package io.osw.modules.sys.controller;

import java.util.Arrays;
import java.util.Map;
import java.util.Date;
import io.osw.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


import io.osw.modules.sys.entity.TblPoHeaderEntity;
import io.osw.modules.sys.service.TblPoHeaderService;
import io.osw.common.utils.PageUtils;
import io.osw.common.utils.R;



/**
 * 采购单头表
 *
 * @author guxiaoguang
 * @email xuebai864627555@gmail.com
 * @date 2019-01-13 17:01:27
 */
@RestController
@RequestMapping("sys/tblpoheader")
public class TblPoHeaderController extends AbstractController{
    @Autowired
    private TblPoHeaderService tblPoHeaderService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:tblpoheader:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = tblPoHeaderService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{poHeaderId}")
    @RequiresPermissions("sys:tblpoheader:info")
    public R info(@PathVariable("poHeaderId") Long poHeaderId){
        TblPoHeaderEntity tblPoHeader = tblPoHeaderService.selectById(poHeaderId);

        return R.ok().put("tblPoHeader", tblPoHeader);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:tblpoheader:save")
    public R save(@RequestBody TblPoHeaderEntity tblPoHeader){
        tblPoHeader.setCreateTime(new Date());
        tblPoHeader.setCreateBy(getUserId());
        tblPoHeaderService.insert(tblPoHeader);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:tblpoheader:update")
    public R update(@RequestBody TblPoHeaderEntity tblPoHeader){
        ValidatorUtils.validateEntity(tblPoHeader);
        tblPoHeader.setUpdateTime(new Date());
        tblPoHeader.setUpdateBy(getUserId());
        tblPoHeaderService.updateAllColumnById(tblPoHeader);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:tblpoheader:delete")
    public R delete(@RequestBody Long[] poHeaderIds){
        tblPoHeaderService.deleteBatchIds(Arrays.asList(poHeaderIds));

        return R.ok();
    }

}
